def Pretreatment(cleartext):#预处理
    pcleartext=''
    for i in cleartext:
        pcleartext+="{0:08b}".format(ord(i))
    L = len(pcleartext)
    if(len(pcleartext)<448):
        pcleartext+='1'
    while(len(pcleartext)<448):
        pcleartext+='0'
    L="{0:064b}".format(L)
    pcleartext+=L
    return pcleartext

def xor_b(a, b):#字符串异或函数
    result = ''
    for i in range(len(a)):
        if a[i] == b[i]:
            result += "0"
        else:
            result += "1"
    return result

def bitwise_y(s1, s2):#字符串与函数
    result = ''
    for i in range(len(s1)):
        if s1[i] == "1" and s2[i] == "1":
            result += "1"
        else:
            result += "0"
    return result

def bitwise_h(s1, s2):#字符串或函数
    result = ''
    for i in range(len(s1)):
        if s1[i] == "1" or s2[i] == "1":
            result += "1"
        else:
            result += "0"
    return result

def bitwise_not(s):#字符串按位取反
    result = ''
    for char in s:
        if char == "0":
            result += "1"
        else:
            result += "0"
    return result

def bitwise_add(s1, s2):
    carry = 0
    result = ''
    for i in range(len(s1) - 1, -1, -1):
        bit_sum = int(s1[i]) + int(s2[i]) + carry
        result = str(bit_sum % 2) + result
        carry = bit_sum//2
    # 处理最终结果长度不足32位的情况，在高位补0
    while len(result) < 32:
        result = "0" + result
    return result

def Compression(cleartext):#压缩函数
    A='01100111010001010010001100000001'
    B='11101111110011011010101110001001'
    C='10011000101110101101110011111110'
    D='00010000001100100101010001100111'
    E='11000011110100101110000111110000'
    A_a='01100111010001010010001100000001'
    B_b='11101111110011011010101110001001'
    C_c='10011000101110101101110011111110'
    D_d='00010000001100100101010001100111'
    E_e='11000011110100101110000111110000'
    W = list(range(80))
    for i in range(16):
        W[i] = cleartext[32*i:32*i+32]
    for i in range(16,80):
        W_middle=''
        W_middle = xor_b(xor_b(xor_b(W[i-16],W[i-14]),W[i-8]),W[i-3])
        W_1 = W_middle[1:] + W_middle[:1]
        W[i] = W_1
    for i in range(20):
        K = '01011010100000100111100110011001'
        temp=''
        EF = bitwise_add(E,bitwise_h(bitwise_y(B,C),bitwise_y(bitwise_not(B),D)))
        SA=A[5:]+A[:5]
        EFS = bitwise_add(EF,SA)
        EFSW = bitwise_add(EFS,W[i])
        temp = bitwise_add(EFSW,K)
        E = D
        D = C
        C = B[30:] + B[:30]
        B = A
        A = temp
        print(A,B,C,D,E)
    for i in range(20,40):
        K = '01101110110110011110101110100001'
        temp=''
        temp = bitwise_add(bitwise_add(bitwise_add(bitwise_add(E,xor_b(xor_b(B,C),D)),A[5:]+A[:5]),W[i]),K) 
        E = D
        D = C
        C = B[30:] + B[:30]
        B = A
        A = temp
        print(A,B,C,D,E)
    for i in range(40,60):
        K = '10001111000110111011110011011100'
        temp=''
        temp = bitwise_add(bitwise_add(bitwise_add(bitwise_add(E,bitwise_h(bitwise_h(bitwise_y(B,C),bitwise_y(B,D)),bitwise_y(C,D))),A[5:]+A[:5]),W[i]),K) 
        E = D
        D = C
        C = B[30:] + B[:30]
        B = A
        A = temp
        print(A,B,C,D,E)
    for i in range(60,80):
        K = '11001010011000101100000111010110'
        temp=''
        temp = bitwise_add(bitwise_add(bitwise_add(bitwise_add(E,xor_b(xor_b(B,C),D)),A[5:]+A[:5]),W[i]),K)
        E = D
        D = C
        C = B[30:] + B[:30]
        B = A
        A = temp
        print(A,B,C,D,E)
    ciphertext=''
    ciphertext += bitwise_add(A_a,A)
    ciphertext += bitwise_add(B_b,B)
    ciphertext += bitwise_add(C_c,C)
    ciphertext += bitwise_add(D_d,D)
    ciphertext += bitwise_add(E_e,E)
    return ciphertext

cleartext = input('请输入小于512bit的数据:')
cleartext = Pretreatment(cleartext)
ciphertext = Compression(cleartext)
print(ciphertext)